﻿<cfscript>
/** 
* ORM StudentSecondDegree
* 
* @hint "Hibernate persistenter t_student_secdegree. 学生修读双学位信息" 
* 
*/ 

component 
	displayname="public.service.orm.senate.StudentSecondDegree" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="StudentSecondDegree" 
	table="t_student_secdegree"
	{

	property type="string" name="SecDegreeID" column="stusec_id" fieldtype="id" generator="assigned" hint="双学位修读编号";

	property type="string" name="Grade" column="grade" hint="年级";	
	property type="string" name="SubjectDirection" column="sbj_direction" hint="专业方向号";

	property type="numeric" name="Credit" column="credit" hint="已获得双学位学分";
	
	property type="string" name="TimeSignedUp" column="signedup" hint="学生申请时间";
	property type="string" name="TimeReviewed" column="reviewed" hint="复审时间";
	property type="string" name="CurrentStat" column="stat" hint="双学位修读状态";

	property name="Subject" fieldtype="many-to-one" fkcolumn="sbj_id" cfc="Subject"  hint="专业";
	property name="Student" fieldtype="many-to-one" fkcolumn="stu_id" cfc="Student"  hint="学生";

	/**
	* @hint "自定义主键规则"
	* 
	* @Grade "年级"
	*/
	public string function getNextID( required string Grade ) output=false {
		
		var nextID = arguments.Grade & "," & numberFormat(1, "0____");
		var checkArray = ORMExecuteQuery("select SecDegreeID from StudentSecondDegree 
											where Grade = :grade 
											order by SecDegreeID desc", { grade=arguments.Grade }, { maxResults=1 });
		
		/* 
			主键生成规则 VARCHAR(12)
			
			年级 , 5位为流水号
		*/
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = arguments.Grade & "," & numberFormat((right(checkArray[1], 5) + 1), "0____");
			
		}

		return nextID;
		
	}
	
}

</cfscript>